

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="MiaoHao-oops">
  <meta name="keywords" content="">
  
    <meta name="description" content="语法分析的自底向上分析技术中，LR(k)是常用的文法分类方法，而LR(0)则是一切方法的基础。本文将介绍如何构建LR(0)分析器中核心的LR(0)分析表。">
<meta property="og:type" content="article">
<meta property="og:title" content="LR(0)分析方法">
<meta property="og:url" content="http://miaohao-oops.github.io/2022/03/29/LR-0-%E5%88%86%E6%9E%90%E6%96%B9%E6%B3%95/index.html">
<meta property="og:site_name" content="Miao&#39;s Blog">
<meta property="og:description" content="语法分析的自底向上分析技术中，LR(k)是常用的文法分类方法，而LR(0)则是一切方法的基础。本文将介绍如何构建LR(0)分析器中核心的LR(0)分析表。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-03-29T01:16:46.000Z">
<meta property="article:modified_time" content="2023-10-25T04:38:40.119Z">
<meta property="article:author" content="MiaoHao-oops">
<meta property="article:tag" content="编译原理">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>LR(0)分析方法 - Miao&#39;s Blog</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"miaohao-oops.github.io","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"appId":"y7tlaLEOoW5C1xBYm8VBo64Q-gzGzoHsz","appKey":"F7gylUefEEtQk24FEbvgfnBi","server_url":"https://y7tlaleo.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":true}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"><link rel="alternate" href="/atom.xml" title="Miao's Blog" type="application/atom+xml">
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>MiaoHao-oops</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="LR(0)分析方法">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-03-29 09:16" pubdate>
        2022年3月29日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      4k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      34 分钟
    </span>
  

  
  
    
      <!-- LeanCloud 统计文章PV -->
      <span id="leancloud-page-views-container" class="post-meta" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="leancloud-page-views"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">LR(0)分析方法</h1>
            
            <div class="markdown-body">
              <h2 id="基本概念">基本概念</h2>
<h3 id="项目-item">项目 item</h3>
<blockquote>
<p>项目是对文法中产生式的扩展，通过在产生式右部添加<span
class="math inline">\(\cdot\)</span>的方法来表示语法分析器在分析过程中的某个状态。</p>
</blockquote>
<p>例子：</p>
<p>对于产生式<span class="math inline">\(A\rightarrow \alpha
X\)</span>，它产生以下几个项：</p>
<p><span class="math display">\[
\begin{align}
A&amp;\rightarrow \cdot \alpha X &amp;(1)\\
A&amp;\rightarrow \alpha \cdot X &amp;(2)\\
A&amp;\rightarrow \alpha X \cdot &amp;(3)\\
\end{align}
\]</span></p>
<p>其中，</p>
<ul>
<li><p>式<span
class="math inline">\((1)\)</span>的点号右侧是一个终结符，意味着在当前状态下，分析器期待从输入流中读入符号<span
class="math inline">\(\alpha\)</span>，因此它被定义为一个<strong>移入项</strong>。</p></li>
<li><p>式<span
class="math inline">\((2)\)</span>中点号右侧是一个非终结符，此时分析器期待后面的输入归约得到非终结符<span
class="math inline">\(X\)</span>，因此它被定义为一个<strong>待约项</strong>。</p></li>
<li><p>式<span
class="math inline">\((3)\)</span>的点号位于整个产生式的结尾，此时意味着分析器将进行归约操作，将<span
class="math inline">\(\alpha X\)</span>归约为<span
class="math inline">\(A\)</span>，因此它被定义为一个<strong>归约项</strong>。</p></li>
</ul>
<h3 id="增广文法-augmented-grammar">增广文法 augmented grammar</h3>
<p>为了得到唯一的终止产生式，定义一个文法<span
class="math inline">\(G\)</span>的增广文法<span
class="math inline">\(G^{\prime}\)</span>：</p>
<blockquote>
<p>对于文法<span class="math inline">\(G\)</span>的开始符号<span
class="math inline">\(S\)</span>，将产生式<span
class="math inline">\(S^{\prime}\rightarrow S\)</span>添加到<span
class="math inline">\(G\)</span>中，就得到了文法<span
class="math inline">\(G^{\prime}\)</span>。</p>
</blockquote>
<p>这样，当分析器进入状态<span
class="math inline">\(S^{\prime}\rightarrow
S\cdot\)</span>时，如果输入流已经读完，就表示进入了接受状态。</p>
<h3 id="textclosure函数"><span
class="math inline">\(\text{CLOSURE}\)</span>函数</h3>
<p><span
class="math inline">\(\text{CLOSURE}\)</span>函数将一个项目集合映射到另一个项目集合，它的输入是项目集合<span
class="math inline">\(I\)</span>，输出是该项目集合的闭包<span
class="math inline">\(\text{CLOSURE}(I)\)</span>。它的意义在于将一些在状态上等价的项聚集起来形成一个状态，而不是对于文法的每一个项作为一个状态，避免语法分析器的状态数过多。定义<span
class="math inline">\(\text{CLOSURE}(I)\)</span>：</p>
<blockquote>
<ol type="1">
<li>初始，<span class="math inline">\(\text{CLOSURE}(I) =
\phi\)</span></li>
<li><span class="math inline">\(\text{CLOSURE}(I) =
\text{CLOSURE}(I)\cup I\)</span></li>
<li>如果<span class="math inline">\(A\rightarrow \alpha \cdot B \beta
\in \text{CLOSURE}(I)\)</span>，并且<span class="math inline">\(\exists
B\rightarrow \cdot \gamma \notin \text{CLOSURE}(I)\)</span>，那么<span
class="math inline">\(\text{CLOSURE}(I) = \text{CLOSURE}(I)\cup
B\rightarrow \cdot \gamma\)</span></li>
</ol>
</blockquote>
<p>不断重复<span
class="math inline">\((3)\)</span>直到没有新的项能添加到<span
class="math inline">\(\text{CLOSURE}(I)\)</span>中。上面各式的含义是：</p>
<ul>
<li><p><span class="math inline">\((2)\)</span>的含义是所有<span
class="math inline">\(I\)</span>中的项都在<span
class="math inline">\(I\)</span>的闭包中</p></li>
<li><p><span class="math inline">\((3)\)</span>的含义是如果<span
class="math inline">\(\text{CLOSURE}(I)\)</span>中某个项的点号的右侧是一个非终结符，那么以该非终结符为左部且点号在右部最左侧的项也在<span
class="math inline">\(\text{CLOSURE}(I)\)</span>中。进一步也就是说如果此时分析器期待对非终结符<span
class="math inline">\(B\)</span>的归约，那么它也同样期待着由<span
class="math inline">\(B\)</span>产生的那些符号，因为只有那些符号才能归约成<span
class="math inline">\(B\)</span>。</p></li>
</ul>
<h3 id="textgoto函数"><span
class="math inline">\(\text{GOTO}\)</span>函数</h3>
<p><span
class="math inline">\(\text{GOTO}\)</span>函数也将一个项目集合映射到另一个项目集合，它的输入是项目集合<span
class="math inline">\(I\)</span>和一个文法符号<span
class="math inline">\(X\)</span>，输出是该项目集合中所有项遇到文法符号<span
class="math inline">\(X\)</span>后所有后继项的闭包。</p>
<blockquote>
<p>后继项：对于项<span class="math inline">\(A\rightarrow X\cdot
YZ\)</span>而言，它的后继项就是将点号移动到项右部的下一个文法符号，即<span
class="math inline">\(A\rightarrow XY\cdot Z\)</span>。</p>
</blockquote>
<p>它的意义是求出分析器状态机中的所有状态转移。定义<span
class="math inline">\(\text{GOTO}\)</span>函数：</p>
<blockquote>
<p><span class="math inline">\(\text{GOTO}(I, X) =
\text{CLOSURE}(\{A\rightarrow \alpha X\cdot \beta \ |\ \forall
A\rightarrow \alpha \cdot X \beta \in I \})\)</span></p>
</blockquote>
<h3 id="规范textlr0项集族-canonical-lr0-collection">规范<span
class="math inline">\(\text{LR}(0)\)</span>项集族 canonical LR(0)
collection</h3>
<p>所谓项集族，指的是项目集合的集合，也就是说项集族中每一个元素都是一个项目的集合。利用<span
class="math inline">\(\text{CLOSURE}\)</span>函数和<span
class="math inline">\(\text{GOTO}\)</span>函数，可以构造出一个文法的规范<span
class="math inline">\(\text{LR}(0)\)</span>项集族。定义规范<span
class="math inline">\(\text{LR}(0)\)</span>项集族：</p>
<blockquote>
<p><span class="math inline">\(C = \{I_{0}\}\cup \{I\ |\ \exists J\in C,
X\in V_{N}\cup V_{T}, I = \text{GOTO}(J, X)\}\)</span></p>
</blockquote>
<p>上面表达式的含义是：</p>
<ul>
<li><p><span class="math inline">\(C\)</span>中包含了项<span
class="math inline">\(S^{\prime}\rightarrow \cdot
S\)</span>的闭包。</p></li>
<li><p>对<span class="math inline">\(C\)</span>中的每一个项目集合<span
class="math inline">\(I\)</span>和文法中每一个符号<span
class="math inline">\(X\)</span>，如果<span
class="math inline">\(\text{GOTO}(I, X)\)</span>不在<span
class="math inline">\(C\)</span>中，则将其添加到<span
class="math inline">\(C\)</span>中。</p></li>
</ul>
<h2 id="textlr0分析器"><span
class="math inline">\(\text{LR}(0)\)</span>分析器</h2>
<h3 id="textlr0分析表的结构"><span
class="math inline">\(\text{LR}(0)\)</span>分析表的结构</h3>
<p><span
class="math inline">\(\text{LR}(0)\)</span>分析表是一个二维表格，它的行数等于文法<span
class="math inline">\(G\)</span>的规范<span
class="math inline">\(\text{LR}(0)\)</span>项集族中元素个数，列数等于<span
class="math inline">\(G\)</span>中文法符号的个数。分析表中的每一个单元表示在某个状态下遇到某个文法符号时，下一步需要进行的操作。整个分析表被划分为<span
class="math inline">\(\text{ACTION}\)</span>和<span
class="math inline">\(\text{GOTO}\)</span>两个区域，落入对应区域的单元分别表示遇到终结符和非终结符时所进行的操作。</p>
<p>对于<span class="math inline">\(\text{ACTION}\)</span>：</p>
<ul>
<li><p>如果为<span
class="math inline">\(s_{i}\)</span>，则表示移入（shift）操作，分析器将输入指针指向的符号移入符号栈，然后将状态<span
class="math inline">\(S_{i}\)</span>移入状态栈。</p></li>
<li><p>如果为<span
class="math inline">\(r_{i}\)</span>，则表示归约（reduce）操作，分析器将使用第<span
class="math inline">\(i\)</span>个产生式对符号栈顶的句柄进行归约操作。</p></li>
</ul>
<p>对于<span
class="math inline">\(\text{GOTO}\)</span>，单元格中所有的元素都是数字，<span
class="math inline">\(j = \text{GOTO}[S_{i}, X]\)</span>表示状态<span
class="math inline">\(S_{i}\)</span>遇到栈顶为非终结符<span
class="math inline">\(X\)</span>时将状态<span
class="math inline">\(S_{j}\)</span>入栈。</p>
<h3 id="textlr0分析器的结构"><span
class="math inline">\(\text{LR}(0)\)</span>分析器的结构</h3>
<p><span
class="math inline">\(\text{LR}(0)\)</span>分析器包含4个主要部分：</p>
<ul>
<li><p>输入缓冲</p></li>
<li><p>符号和状态栈</p></li>
<li><p><span class="math inline">\(\text{LR}(0)\)</span>分析表</p></li>
<li><p>驱动程序</p></li>
</ul>
<p>它的运行中的格局是：</p>
<ol type="1">
<li>初始格局为：</li>
</ol>
<p><span class="math display">\[\begin{align}
&amp;S_{0} \\
&amp;\$ &amp;a_{1}a_{2}\cdots a_{n}\$\\
\end{align}\]</span></p>
<p>其中<span class="math inline">\(S_{0}\)</span>表示初始状态，对应<span
class="math inline">\(S^{\prime}\rightarrow \cdot
S\)</span>的项目集闭包。</p>
<ol start="2" type="1">
<li>假设运行时的一个格局是：</li>
</ol>
<p><span class="math display">\[\begin{align}
&amp;S_{0}S_{1}S_{2}\cdots S_{m} \\
&amp;\$ X_{1}X_{2}\cdots X_{m} &amp;a_{i}a_{i + 1}\cdots a_{n}\$\\
\end{align}\]</span></p>
<ul>
<li><p>若<span class="math inline">\(\text{ACTION}[S_{m}, a_{i}] =
s_{x}\)</span>，则进行移入操作，格局变为： <span
class="math display">\[\begin{align}
&amp;S_{0}S_{1}S_{2}\cdots S_{m}S_{x} \\
&amp;\$ X_{1}X_{2}\cdots X_{m}a_{i} &amp;a_{i + 1}\cdots a_{n}\$\\
  \end{align}\]</span></p></li>
<li><p>若<span class="math inline">\(\text{ACTION}[S_{m}, a_{i}] =
r_{x}\)</span>，则进行归约操作，使用第<span
class="math inline">\(x\)</span>个产生式<span
class="math inline">\(A\rightarrow X_{m - (k - 1)}\cdots
X_{m}\)</span>，格局变为： <span class="math display">\[\begin{align}
&amp;S_{0}S_{1}S_{2}\cdots S_{m - k} \\
&amp;\$ X_{1}X_{2}\cdots X_{m - k}A &amp;a_{i}a_{i + 1}\cdots a_{n}\$\\
  \end{align}\]</span></p></li>
</ul>
<p>而后查找<span class="math inline">\(\text{GOTO}\)</span>表，若<span
class="math inline">\(\text{GOTO}[S_{m - k}, A] =
y\)</span>，则进行状态转移，格局变为：</p>
<p><span class="math display">\[\begin{align}
&amp;S_{0}S_{1}S_{2}\cdots S_{m - k}S_{y} \\
&amp;\$ X_{1}X_{2}\cdots X_{m - k}A &amp;a_{i}a_{i + 1}\cdots a_{n}\$\\
  \end{align}\]</span></p>
<ul>
<li>若<span class="math inline">\(\text{ACTION}[S_{m}, a_{i}] =
\text{acc}\)</span>，则分析成功。</li>
<li>若<span class="math inline">\(\text{ACTION}[S_{m}, a_{i}] =
\text{err}\)</span>，则分析失败。</li>
</ul>
<h3 id="构造textlr0分析表">构造<span
class="math inline">\(\text{LR}(0)\)</span>分析表</h3>
<p>构造<span
class="math inline">\(\text{LR}(0)\)</span>分析表的方法是：</p>
<ol type="1">
<li><p>首先求文法<span class="math inline">\(G\)</span>的<span
class="math inline">\(\text{LR}(0)\)</span>项集族<span
class="math inline">\(C\)</span></p></li>
<li><p>对于<span class="math inline">\(C\)</span>中的每一个项目集<span
class="math inline">\(I\)</span>：</p>
<ol type="1">
<li><p>如果<span class="math inline">\(\text{GOTO}(I, \alpha) =
I^{\prime}\)</span>，则<span class="math inline">\(\text{ACTION}[I,
\alpha] = S_{I^{\prime}}\)</span></p></li>
<li><p>如果<span class="math inline">\(\text{GOTO}(I, A) =
I^{\prime}\)</span>，则<span class="math inline">\(\text{GOTO}[I, A] =
I^{\prime}\)</span></p></li>
<li><p>如果<span class="math inline">\(I\)</span>中有归约项，则<span
class="math inline">\(\forall \alpha, \text{ACTION}[I, \alpha] =
r_{x}\)</span>，其中<span
class="math inline">\(x\)</span>为归约项对应产生式的编号</p></li>
</ol></li>
</ol>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/note/">note</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E7%BC%96%E8%AF%91%E5%8E%9F%E7%90%86/">编译原理</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/04/01/%E4%B8%89%E6%9C%88%E4%B8%89%E5%8D%81%E4%B8%80%E6%97%A5%E4%BA%8E%E8%A5%BF%E5%8C%97%E9%A3%9F%E5%A0%82%E7%94%A8%E5%8D%88%E9%A4%90%E4%BD%9C%E8%AF%97%E4%B8%80%E9%A6%96/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">三月三十一日于西北食堂用午餐作诗一首</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/07/nju-pa%E6%91%B8%E9%B1%BC%E8%AE%B04-%E6%8C%87%E4%BB%A4%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/">
                        <span class="hidden-mobile">nju-pa摸鱼记4-指令的生命周期</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"y7tlaLEOoW5C1xBYm8VBo64Q-gzGzoHsz","appKey":"F7gylUefEEtQk24FEbvgfnBi","path":"window.location.pathname","placeholder":"此处留言","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          Fluid.plugins.initFancyBox('#valine .vcontent img:not(.vemoji)');
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> && <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- LeanCloud 统计PV -->
        <span id="leancloud-site-pv-container" style="display: none">
            总访问量 
            <span id="leancloud-site-pv"></span>
             次
          </span>
      
      
        <!-- LeanCloud 统计UV -->
        <span id="leancloud-site-uv-container" style="display: none">
            总访客数 
            <span id="leancloud-site-uv"></span>
             人
          </span>
      

    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>





  

  
    <!-- MathJax -->
    <script>
      MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']]
        },
        loader: {
          load: ['ui/lazy']
        },
        options: {
          renderActions: {
            findScript: [10, doc => {
              document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
                const display = !!node.type.match(/; *mode=display/);
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
                const text = document.createTextNode('');
                node.parentNode.replaceChild(text, node);
                math.start = { node: text, delim: '', n: 0 };
                math.end = { node: text, delim: '', n: 0 };
                doc.math.push(math);
              });
            }, '', false],
            insertedScript: [200, () => {
              document.querySelectorAll('mjx-container').forEach(node => {
                let target = node.parentNode;
                if (target.nodeName.toLowerCase() === 'li') {
                  target.parentNode.classList.add('has-jax');
                }
              });
            }, '', false]
          }
        }
      };
    </script>

    <script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" ></script>

  





  <script  src="https://cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js" ></script>
  <script>
    if (window.mermaid) {
      mermaid.initialize({"theme":"default"});
    }
  </script>




  

  

  

  

  

  





<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</body>
</html>
